#include <iostream>

#include <boost/thread/mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/thread.hpp>

int shared_i = 0;
boost::mutex i_mutex;

void do_inc() {
	for (std::size_t i = 0; i < 30000; ++i) {
		int i_snapshot;
		{
			boost::lock_guard<boost::mutex> lock(i_mutex);
			i_snapshot = ++shared_i;
		}
		std::cout << "do_inc:" << i_snapshot << std::endl;
	}
}

void do_dec() {
	for (std::size_t i = 0; i < 30000; ++i) {
		int i_snapshot;
		{
			boost::lock_guard<boost::mutex> lock(i_mutex);
			i_snapshot = --shared_i;
		}
		std::cout << "do_dec:" << i_snapshot << std::endl;
	}
}

int main()
{
	boost::thread t1(&do_inc);
	boost::thread t2(&do_dec);
	t1.join();
	t2.join();
	std::cout << "==== 1 ====" << std::endl;
	std::cout << "shared_i:" << shared_i << "    " << std::endl;
	return 0;
}